package com.alm.token.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alm.token.ConStant;
import com.alm.token.GlideApp;
import com.alm.token.R;
import com.alm.token.base.BaseActivity;
import com.alm.token.base.BaseAdapter;
import com.alm.token.common.RefreshLoadMoreManager;
import com.alm.token.ui.data.bean.LH2OrderDetailsData;
import com.alm.token.ui.data.bean.MiningWalletTypeIndexData;
import com.alm.token.ui.data.bean.RegisterData;
import com.alm.token.ui.data.bean.StakingMiningMoneyDrawIndexData;
import com.alm.token.ui.data.bean.StakingOrderAddData;
import com.alm.token.ui.data.bean.StakingOrderAppendData;
import com.alm.token.ui.data.bean.StakingOrderIndexData;
import com.alm.token.ui.data.bean.UserWalletData;
import com.alm.token.ui.persenter.MyPreenter;
import com.alm.token.ui.view.StakingView;
import com.alm.token.utils.ActionBarHelper;
import com.alm.token.utils.CommonUtil;
import com.alm.token.utils.EmptyUtils;
import com.alm.token.utils.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import baibeiwallet.event.RefreshWalletEvent;
import baibeiwallet.utils.DialogUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.alm.token.utils.CommonUtil.formatSeconds;

public class StakingOrderIndexActivity extends BaseActivity implements StakingView<StakingOrderIndexData> {


    @BindView(R.id.img_moneyTypeIcon)
    ImageView imgMoneyTypeIcon;
    @BindView(R.id.tv_moneyType)
    TextView tvMoneyType;
    @BindView(R.id.tv_tv1)
    TextView tvTv1;
    @BindView(R.id.edt_inputmoney)
    EditText edtInputmoney;
    @BindView(R.id.tv_miovalue)
    TextView tvMiovalue;
    @BindView(R.id.rly_inputbody)
    RelativeLayout rlyInputbody;
    @BindView(R.id.tv_orderLevel1)
    TextView tvOrderLevel1;
    @BindView(R.id.ly_xinjibody1)
    LinearLayout lyXinjibody1;
    @BindView(R.id.tv_impawnmoney)
    TextView tvImpawnmoney;
    @BindView(R.id.tv_impawn_miovalue)
    TextView tvImpawnMiovalue;
    @BindView(R.id.rly_impawnbody)
    RelativeLayout rlyImpawnbody;
    @BindView(R.id.tv_order_openNeedDayNum)
    TextView tvOrderOpenNeedDayNum;
    @BindView(R.id.tv_order_sucDay)
    TextView tvOrderSucDay;
    @BindView(R.id.tv_order_waitNum)
    TextView tvOrderWaitNum;
    @BindView(R.id.ly_waitbody)
    LinearLayout lyWaitbody;
    @BindView(R.id.tv_order_staue)
    TextView tvOrderStaue;
    @BindView(R.id.rly_staking_stauebody)
    RelativeLayout rlyStakingStauebody;
    @BindView(R.id.tv_tv2)
    TextView tvTv2;
    @BindView(R.id.tv_pay_time)
    TextView tvPayTime;
    @BindView(R.id.rly_staking_paytimebody)
    RelativeLayout rlyStakingPaytimebody;

    @BindView(R.id.tv_order_zhouqi)
    TextView tvOrderZhouqi;
    @BindView(R.id.tv_order_yuehua)
    TextView tvOrderYuehua;
    @BindView(R.id.tv_order_expirationdate)
    TextView tvOrderExpirationdate;
    @BindView(R.id.tv_order_continuedDay)
    TextView tvOrderContinuedDay;
    @BindView(R.id.tv_order_shouyi)
    TextView tvOrderShouyi;
    @BindView(R.id.tv_shouyi_more)
    TextView tvShouyiMore;
    @BindView(R.id.rly_shouyi_item)
    RelativeLayout rlyShouyiItem;
    @BindView(R.id.tv_order_shenfen)
    TextView tvOrderShenfen;
    @BindView(R.id.tv_order_shouxubili)
    TextView tvOrderShouxubili;
    @BindView(R.id.tv_order_shouxu)
    TextView tvOrderShouxu;
    @BindView(R.id.tv_shouxu_more)
    TextView tvShouxuMore;
    @BindView(R.id.rly_shouxu_item)
    RelativeLayout rlyShouxuItem;
    @BindView(R.id.recycler_view_shouyi)
    RecyclerView recyclerViewShouyi;
    @BindView(R.id.ly_orderbody)
    LinearLayout lyOrderbody;
    @BindView(R.id.btn_quantitativeapply_click)
    TextView btnQuantitativeapplyClick;
    @BindView(R.id.btn_quantitativeapply_appendclick)
    TextView btnQuantitativeapplyAppendclick;
    @BindView(R.id.btn_quantitativeapply_closeclick)
    TextView btnQuantitativeapplyCloseclick;
    @BindView(R.id.ly_bottom)
    LinearLayout lyBottom;
    @BindView(R.id.ly_userRolebody)
    LinearLayout lyUserRolebody;
    @BindView(R.id.tv_yuyueorderLevel)
    TextView tvYuyueorderLevel;
    @BindView(R.id.ly_yuyuexinjibody)
    LinearLayout lyYuyuexinjibody;
    @BindView(R.id.tv_order_yuyuezhouqi)
    TextView tvOrderYuyuezhouqi;
    @BindView(R.id.tv_order_yuyueyuehua)
    TextView tvOrderYuyueyuehua;
    @BindView(R.id.ly_yuyueorderbody)
    LinearLayout lyYuyueorderbody;
    @BindView(R.id.id_swipeRefreshLayout)
    SwipeRefreshLayout swipeRefreshLayout;
    @BindView(R.id.tv_impawn_topshow)
    TextView tv_impawn_topshow;

    private StakingOrderIndexData.DataBean data;
    private StakingOrderIndexData.DataBean.WaitObjBean waitObj;
    private StakingOrderIndexData.DataBean.UserRoleBean userRole;
    private List<StakingOrderIndexData.DataBean.GoodsBean> goods;
    private List<StakingOrderIndexData.DataBean.OrderBean.AppendListBean> appendList;
    private StakingOrderIndexData.DataBean.OrderBean order;
    private StakingOrderIndexData.DataBean.OrderBean.PayOrderVoBean payOrderVo;
    private int moneyType;
    private String orderSn;
    private double mioWallet, mioPrice, number;
    private int ActivityForResultCode = 1;
    private RefreshLoadMoreManager<StakingOrderIndexData.DataBean.OrderBean.TypeOrderVosBean> managerZonge;
    List<StakingOrderIndexData.DataBean.OrderBean.TypeOrderVosBean> typeOrderVos = new ArrayList<>();

    public StakingOrderIndexActivity() {
    }

    @Override
    protected MyPreenter initPreenter() {
        return new MyPreenter(this);
    }


    @Override
    protected int getContentViewId() {
        return R.layout.activity_staking_orderindex;
    }

    @Override
    protected void initVariables() {
        moneyType = getIntent().getIntExtra("moneyType", 0);
        orderSn = getIntent().getStringExtra("orderSn");
    }


    @Override
    protected void initViews() {
        new ActionBarHelper(this).setTitle(getString(R.string.fortune_hint_poskuang)).setRightText(getString(R.string.title_hint_item13), this);
        initManager();
    }

    private void initManager() {
        OrderAdapter adapterZonge = new OrderAdapter(this);
        managerZonge = new RefreshLoadMoreManager.Builder(this)
                .setAdapter(adapterZonge)
                .setRecyclerView(recyclerViewShouyi)
                .build();
        adapterZonge.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (EmptyUtils.isNotEmpty(typeOrderVos) && typeOrderVos.size() > position) {

                    Intent intent = new Intent(StakingOrderIndexActivity.this, StakingShouyiByDayActivity.class);
                    intent.putExtra("moneyType", String.valueOf(typeOrderVos.get(position).getMoneyType()));
                    intent.putExtra("orderSn", orderSn);
                    startActivity(intent);

                }
            }
        });
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swipeRefreshLayout.setRefreshing(false);
                loadData();
            }
        });
        recyclerViewShouyi.setNestedScrollingEnabled(false);
    }

    @Override
    protected void loadData() {
        preenter.getStakingOrderIndexData(String.valueOf(moneyType), orderSn);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rightItem:
                startActivity(StakingOrderHistoryActivity.class);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == ActivityForResultCode) {
            if (resultCode == QuantitativeOrderOpenAddActivity.AddAppendSucc
                    || resultCode == QuantitativeOrderDetailActivity.AppendSucc) {
//                showToast("添加成功，刷新列表");
                loadData();
                setResult(QuantitativeOrderOpenAddActivity.AddAppendSucc);
//                finish();
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void getData(StakingOrderIndexData stakingOrderIndexData) {
        if (stakingOrderIndexData.getStatus() == 0) {
            data = stakingOrderIndexData.getData();
            if (EmptyUtils.isNotEmpty(data)) {
                // 订单处于待支付，排队中 或 为null
                waitObj = data.getWaitObj();
                // 当订单可关闭时
                userRole = data.getUserRole();
                // 可选择的套餐 当order 不为null时有数据
                goods = data.getGoods();
//                // 可追加币种
//                appendList = data.getAppendList();
                // order 不为null 有已预约订单
                order = data.getOrder();
            }

            if (EmptyUtils.isNotEmpty(waitObj) && (EmptyUtils.isEmpty(order) || order.getStatus() == 1 || order.getStatus() == 2)) {
                lyWaitbody.setVisibility(View.VISIBLE);
                tvOrderOpenNeedDayNum.setText(waitObj.getOpenNeedDayNum() + getString(R.string.lh20_hint_day));
                tvOrderSucDay.setText(waitObj.getSucDay());
                tvOrderWaitNum.setText(waitObj.getWaitNum() + getString(R.string.staking_hint_staking_people));
            } else {
                lyWaitbody.setVisibility(View.GONE);
            }


            if (EmptyUtils.isNotEmpty(order) && EmptyUtils.isNotEmpty(userRole) && order.getStatus() == 3) {
                lyUserRolebody.setVisibility(View.VISIBLE);
                tvOrderShenfen.setText(userRole.getUserRole());
                tvOrderShouxubili.setText(userRole.getTakeOffRatio() + "%");
                tvOrderShouxu.setText(userRole.getCloseServiceCharge() + "MIO");
            } else {
                lyUserRolebody.setVisibility(View.GONE);
            }

            GlideApp.with(this).load(data.getMoneyTypeIcon())
                    .error(R.drawable.icon_arctic).into(imgMoneyTypeIcon);
            tvMoneyType.setText(data.getMoneyType());
            mioWallet = data.getMioWallet();
            mioPrice = data.getMioPrice();
            edtInputmoney.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    if (s.toString().contains(".")) {
                        if (s.length() - 1 - s.toString().indexOf(".") > 4) {
                            s = s.toString().subSequence(0, s.toString().indexOf(".") + 5);
                            edtInputmoney.setText(s);
                            edtInputmoney.setSelection(s.length());
                        }
                    }
                    if (s.toString().trim().substring(0).equals(".")) {
                        s = "0" + s;
                        edtInputmoney.setText(s);
                        edtInputmoney.setSelection(2);
                    }

                    if (s.toString().startsWith("0")
                            && s.toString().trim().length() > 1) {
                        if (!s.toString().substring(1, 2).equals(".")) {
                            edtInputmoney.setText(s.subSequence(0, 1));
                            edtInputmoney.setSelection(1);
                            return;
                        }
                    }

                    number = Double.parseDouble(s != null ? (!s.toString().isEmpty() ? s.toString() : "0") : "0");

                    if (number > mioWallet * mioPrice) {
                        showToast(getString(R.string.conversioncurrency_hint1_warn6));
                    }
                    tvMiovalue.setText("≈ " + CommonUtil.saveToPoint4WithNo(number / mioPrice) + "MIO");
                    mathNumber();
                }

                @Override
                public void afterTextChanged(Editable s) {

                }
            });

            if (EmptyUtils.isNotEmpty(order)) {
                orderSn = order.getOrderSn();
                typeOrderVos = order.getTypeOrderVos();
                if (EmptyUtils.isNotEmpty(typeOrderVos)) {
                    for (int i = 0; i < typeOrderVos.size(); i++) {
                        typeOrderVos.get(i).setLayoutId(OrderAdapter.LAYOUT_ID);
                    }
                    managerZonge.setData(typeOrderVos);
                    recyclerViewShouyi.setVisibility(View.VISIBLE);
                }
                rlyImpawnbody.setVisibility(View.VISIBLE);
                rlyInputbody.setVisibility(View.GONE);
                if (order.getStatus() != 1 && order.getStatus() != 2) {
                    lyOrderbody.setVisibility(View.VISIBLE);
                } else {
                    lyOrderbody.setVisibility(View.GONE);
                }


                int ll1 = order.getLevel();
                if (ll1 <= lyXinjibody1.getChildCount()) {
                    for (int i = 0; i < lyXinjibody1.getChildCount(); i++) {//4number  i=0-3
                        if (i < ll1) { //i=0 1 2 3  ll1=1 2 3 4
                            lyXinjibody1.getChildAt(i).setVisibility(View.VISIBLE);
                        } else {
                            lyXinjibody1.getChildAt(i).setVisibility(View.GONE);
                        }
                    }
                }
                tvOrderExpirationdate.setText(order.getExpirationTime());
                tvImpawnmoney.setText("≈ $" + CommonUtil.saveToPoint2WithNo(order.getMoney()));
                tvImpawnMiovalue.setText(CommonUtil.saveToPoint4WithNo4(order.getMoney() / mioPrice) + "MIO");
                tvOrderLevel1.setText(order.getLevelName());
                tvOrderZhouqi.setText(order.getCycle() + getString(R.string.lh20_hint_day));
                tvOrderYuehua.setText("≈" + order.getMonthlyEarnings() + "/" + getString(R.string.alphago_hint_month));
                tvOrderContinuedDay.setText(order.getOpeningDays() + getString(R.string.lh20_hint_day));
                tvOrderShouyi.setText(StringUtils.nullToStr0(CommonUtil.saveToPoint4WithNo(order.getRewardMoney())));
            } else {
                lyOrderbody.setVisibility(View.GONE);
                rlyImpawnbody.setVisibility(View.GONE);
                rlyInputbody.setVisibility(View.VISIBLE);
            }
            if (EmptyUtils.isNotEmpty(timer)) {
                timer.cancel();
            }
            if (EmptyUtils.isNotEmpty(order)) {
                if (order.getStatus() == 1) {
                    tv_impawn_topshow.setVisibility(View.VISIBLE);
                    rlyStakingPaytimebody.setVisibility(View.GONE);
                    rlyStakingStauebody.setVisibility(View.VISIBLE);
                    btnQuantitativeapplyClick.setVisibility(View.VISIBLE);
                    btnQuantitativeapplyAppendclick.setVisibility(View.GONE);
                    btnQuantitativeapplyCloseclick.setVisibility(View.GONE);
                    btnQuantitativeapplyClick.setText(getString(R.string.staking_hint_staking_cancleyuyue));
                    btnQuantitativeapplyClick.setTag(getString(R.string.staking_hint_staking_cancleyuyue));
                    btnQuantitativeapplyClick.setBackground(getResources().getDrawable(R.drawable.gradient_btn_unclick));
                } else if (order.getStatus() == 2) {
                    payOrderVo = order.getPayOrderVo();
                    startTimer();
                    tv_impawn_topshow.setVisibility(View.VISIBLE);
                    rlyStakingPaytimebody.setVisibility(View.VISIBLE);
                    rlyStakingStauebody.setVisibility(View.GONE);
                    btnQuantitativeapplyClick.setVisibility(View.GONE);
                    btnQuantitativeapplyAppendclick.setVisibility(View.VISIBLE);
                    btnQuantitativeapplyCloseclick.setVisibility(View.VISIBLE);

                    btnQuantitativeapplyAppendclick.setText(getString(R.string.tv_hint_activity_order_paysubmit1));
                    btnQuantitativeapplyAppendclick.setTag(getString(R.string.tv_hint_activity_order_paysubmit1));

                    btnQuantitativeapplyCloseclick.setText(getString(R.string.staking_hint_staking_cancleyuyue));
                    btnQuantitativeapplyCloseclick.setTag(getString(R.string.staking_hint_staking_cancleyuyue));

                } else if (order.getStatus() == 3) {
                    rlyStakingPaytimebody.setVisibility(View.GONE);
                    rlyStakingStauebody.setVisibility(View.GONE);
                    btnQuantitativeapplyClick.setVisibility(View.GONE);
                    btnQuantitativeapplyAppendclick.setVisibility(View.VISIBLE);
                    btnQuantitativeapplyCloseclick.setVisibility(View.VISIBLE);
                    tv_impawn_topshow.setVisibility(View.GONE);
                    btnQuantitativeapplyAppendclick.setText(getString(R.string.title_hint_item28));
                    btnQuantitativeapplyAppendclick.setTag(getString(R.string.title_hint_item28));
                    btnQuantitativeapplyCloseclick.setText(getString(R.string.staking_hint_closetitle));
                    btnQuantitativeapplyCloseclick.setTag(getString(R.string.staking_hint_closetitle));

                } else if (order.getStatus() == 4 || order.getStatus() == 5) {
                    tv_impawn_topshow.setVisibility(View.GONE);
                    rlyStakingPaytimebody.setVisibility(View.GONE);
                    rlyStakingStauebody.setVisibility(View.GONE);
                    btnQuantitativeapplyClick.setVisibility(View.GONE);
                    btnQuantitativeapplyAppendclick.setVisibility(View.GONE);
                    btnQuantitativeapplyCloseclick.setVisibility(View.GONE);
                } else {
                    tv_impawn_topshow.setVisibility(View.GONE);
                }

            } else {
                rlyStakingPaytimebody.setVisibility(View.GONE);
                rlyStakingStauebody.setVisibility(View.GONE);
                btnQuantitativeapplyClick.setVisibility(View.VISIBLE);
                btnQuantitativeapplyAppendclick.setVisibility(View.GONE);
                btnQuantitativeapplyCloseclick.setVisibility(View.GONE);
            }

        } else {
            showToast(stakingOrderIndexData.getMsg());
        }

    }

    @Override
    protected void onPause() {
        super.onPause();
        if (EmptyUtils.isNotEmpty(timer)) {
            timer.cancel();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (EmptyUtils.isNotEmpty(timer)) {
            timer.cancel();
            timer = null;
        }
    }

    private CountDownTimer timer;
    private long times = 0, refreshTime = -1;

    private void startTimer() {
        times = order.getActivationTime();
        timer = new CountDownTimer(times * 1000, 1000) {
            /**
             * 固定间隔被调用,就是每隔countDownInterval会回调一次方法onTick
             * @param millisUntilFinished
             */
            @Override
            public void onTick(long millisUntilFinished) {
                tvPayTime.setText(formatSeconds(millisUntilFinished / 1000));//结束倒计时

//                        tv_remaining_time.setText(formatTime(millisUntilFinished));
            }

            /**
             * 倒计时完成时被调用
             */
            @Override
            public void onFinish() {
                if (EmptyUtils.isNotEmpty(preenter)) {
                    loadData();
                }
//                        tv_remaining_time.setText("00:00");
            }
        };
        if (times != 0) {
            timer.start();
        }
    }

    private void mathNumber() {
        if (EmptyUtils.isNotEmpty(goods)) {
            for (int j = goods.size() - 1; j >= 0; j--) {

                if (number >= goods.get(j).getGoodsValue()) {
                    int ll1 = j + 1;
                    if (ll1 <= lyYuyuexinjibody.getChildCount()) {
                        for (int i = 0; i < lyYuyuexinjibody.getChildCount(); i++) {//4number  i=0-3
                            if (i < ll1) { //i=0 1 2 3  ll1=1 2 3 4
                                lyYuyuexinjibody.getChildAt(i).setVisibility(View.VISIBLE);
                            } else {
                                lyYuyuexinjibody.getChildAt(i).setVisibility(View.GONE);
                            }
                        }
                    }
                    tvYuyueorderLevel.setText("STKL" + goods.get(j).getLevel());//goods.get(j).getGoodsName()
                    tvOrderYuyueyuehua.setText(goods.get(j).getMonthlyEarnings() + "%/" + getString(R.string.alphago_hint_month));
                    tvOrderYuyuezhouqi.setText(goods.get(j).getCycle() + getString(R.string.lh20_hint_day));
                    lyYuyueorderbody.setVisibility(View.VISIBLE);
                    break;
                } else {
                    lyYuyueorderbody.setVisibility(View.GONE);
                }
            }
//            if (number != 0) {
//                lyYuyueorderbody.setVisibility(View.VISIBLE);
//            } else {
//                lyYuyuexinjibody.setVisibility(View.GONE);
//            }
        }

        if (number > 30000) {
            showToast(getString(R.string.staking_hint_staking_inputmonmey_most) + "$30000");
            edtInputmoney.setText(CommonUtil.saveToPoint2WithNo(30000));
        }
    }

    @Override
    public void jumpToLoginAct(int staue) {
        if (staue == 3) {
//            showToast("需要重新登录!");
//            showToast(getString(R.string.common_relogin));
//            Intent intent = new Intent();
//            intent.setAction(ConStant.EXIT_APP);
//            sendBroadcast(intent);
//            startActivity(BlockWalletLoginActivity.class);
//            finish();
        } else if (staue == 4) {
//            showToast(getString(R.string.paypasw_hint_setpaypsw));
//            Intent intent = new Intent(getActivity(),PayPwdActivity.class);
//            intent.putExtra("PayPwdActivityType",PayPwdActivity.PAYPSW_SET);
//            startActivity(intent);
//            getActivity().finish();
            showToSetPaypswDialog();
        } else if (staue == 666) {
            showToUpdata();
        }
    }

    @Override
    public void onError(String error) {
        showToast(getString(R.string.common_loaderrritry));
    }

    @Override
    public void ShowProgress() {
        showWaitDialog();
    }

    @Override
    public void hideProgress() {
        hideWaitDialog();
    }

    @OnClick({R.id.btn_quantitativeapply_click, R.id.btn_quantitativeapply_appendclick, R.id.btn_quantitativeapply_closeclick,
            R.id.rly_shouyi_item})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rly_shouyi_item:

                if (EmptyUtils.isNotEmpty(typeOrderVos) && typeOrderVos.size() > 0) {
                    Intent intent = new Intent(StakingOrderIndexActivity.this, StakingShouyiByDayActivity.class);
                    intent.putExtra("moneyType", "");
                    intent.putExtra("orderSn", orderSn);
                    startActivity(intent);
                }


//                if (EmptyUtils.isNotEmpty(typeOrderVos)) {
//                    recyclerViewShouyi.setVisibility(recyclerViewShouyi.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
//                }


                break;
            case R.id.btn_quantitativeapply_click:

                if (EmptyUtils.isNotEmpty(btnQuantitativeapplyClick.getTag()) &&
                        ((String) btnQuantitativeapplyClick.getTag())
                                .equalsIgnoreCase(getString(R.string.staking_hint_staking_cancleyuyue))) {

                    //取消排队
                    DialogUtils.enterPayPsw(this, (pwd1) -> {
                        //eth1 mio2
                        preenter.getStakingCancelQueuingData(orderSn, pwd1);
                    });
                } else {
                    //开启  输入100的整数倍
                    if (number % 100 != 0) {
                        showToast(getString(R.string.staking_hint_staking_inputmonmey_hint) + "," + getString(R.string.staking_hint_staking_warm));
                        break;
                    }
                    DialogUtils.enterPayPsw(this, (pwd1) -> {
                        //eth1 mio2
                        preenter.getStakingAddOrderData(String.valueOf(moneyType), number + "", pwd1);
                    });
                }

                break;
            case R.id.btn_quantitativeapply_appendclick:

                if (EmptyUtils.isNotEmpty(btnQuantitativeapplyAppendclick.getTag()) &&
                        ((String) btnQuantitativeapplyAppendclick.getTag())
                                .equalsIgnoreCase(getString(R.string.tv_hint_activity_order_paysubmit1))) {

                    //支付
                    if (EmptyUtils.isNotEmpty(payOrderVo)) {
                        DialogUtils.enterPayPsw(this, (pwd1) -> {
                            //eth1 mio2
                            preenter.getStakingPayOrderData(payOrderVo.getOrderSn(), pwd1);
                        });
                    }
                } else {
//                    //追加
                    Intent intent = new Intent(this, StakingOrderAppendActivity.class);
                    intent.putExtra("moneyType", moneyType);
                    intent.putExtra("orderSn", orderSn);
                    startActivityForResult(intent, ActivityForResultCode);

//                    DialogUtils.enterPayPsw(this, (pwd1) -> {
//                        //eth1 mio2
//                        preenter.getStakingAddOrderData(String.valueOf(moneyType), number + "", pwd1);
//                    });
                }

                break;
            case R.id.btn_quantitativeapply_closeclick:

                if (EmptyUtils.isNotEmpty(btnQuantitativeapplyCloseclick.getTag()) &&
                        ((String) btnQuantitativeapplyCloseclick.getTag())
                                .equalsIgnoreCase(getString(R.string.staking_hint_staking_cancleyuyue))) {

                    //取消排队
                    DialogUtils.enterPayPsw(this, (pwd1) -> {
                        //eth1 mio2
                        preenter.getStakingCancelQueuingData(orderSn, pwd1);
                    });
                } else {
//                    //关闭赎回
                    showPopupMenu(btnQuantitativeapplyCloseclick);

//                    DialogUtils.enterPayPsw(this, (pwd1) -> {
//                        //eth1 mio2
//                        preenter.getStakingAddOrderData(String.valueOf(moneyType), number + "", pwd1);
//                    });
                }

                break;

        }


    }

    public class OrderAdapter extends BaseAdapter<StakingOrderIndexData.DataBean.OrderBean.TypeOrderVosBean> {

        public static final int LAYOUT_ID = R.layout.item_staking_order_detail_shouyi_item;

        public OrderAdapter(@NonNull Context context) {
            super(context);
        }

        @Override
        protected void convert(BaseViewHolder helper, StakingOrderIndexData.DataBean.OrderBean.TypeOrderVosBean item, int itemType) {

            helper.setText(R.id.tv_shouyitime, item.getMoneyTypeStr());
            helper.setTextColor(R.id.tv_shouyitime, context.getResources().getColor(R.color.text_2223292));
            helper.setText(R.id.tv_shouymoney, item.getRewardMoney());
            helper.setTextColor(R.id.tv_shouymoney, context.getResources().getColor(R.color.bg_653fac2));
        }

    }

    public void showPopupMenu(View view) {
        //参数View 是设置当前菜单显示的相对于View组件位置，具体位置系统会处理
        PopupMenu popupMenu = new PopupMenu(this, view);
        //加载menu布局
        popupMenu.getMenuInflater().inflate(R.menu.menu_popmenu_closeselect_staking, popupMenu.getMenu());

        //设置menu中的item点击事件
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {

                switch (item.getItemId()) {
                    case R.id.all_close:
                        UserWalletData.DataBean.SysMsgBean sysMsgBean = new UserWalletData.DataBean.SysMsgBean();
                        sysMsgBean.setTitle(getString(R.string.alphago_hint_warn9));
                        sysMsgBean.setContent(getString(R.string.staking_hint_warn10));
                        DialogUtils.showInfor1(StakingOrderIndexActivity.this, sysMsgBean, (pwd) -> {
                            btnQuantitativeapplyCloseclick.setTag("all_close");
                            preenter.getStakingCloseAllOrderData(orderSn);
                        });
                        break;

                    case R.id.some_close:
                        Intent intent = new Intent(StakingOrderIndexActivity.this, StakingOrderCloseNewActivity.class);
                        intent.putExtra("moneyType", moneyType);
                        intent.putExtra("orderSn", orderSn);
                        startActivityForResult(intent, ActivityForResultCode);
//                        Intent intent = new Intent(StakingOrderIndexActivity.this, Quantitative20OrderCloseActivity.class);
//                        intent.putExtra("Ordersn", OrderDetailsDataBean.getOrdersn());
//                        startActivityForResult(intent, ActivityForResultCode);
                        break;

                }
                return true;
            }
        });
        popupMenu.show();
    }

    @Override
    public void getStakingAddOrderData(StakingOrderAddData stakingOrderAddData) {
        if (stakingOrderAddData.getStatus() == 0) {
            orderSn = stakingOrderAddData.getData().getOrderSn();
            setResult(QuantitativeOrderDetailActivity.AppendSucc);
            edtInputmoney.setText("");
            loadData();
        } else {
            showToast(stakingOrderAddData.getMsg());
        }
    }

    @Override
    public void getStakingCancelQueuingData(RegisterData registerData) {
        showToast(registerData.getMsg());
        if (registerData.getStatus() == 0) {
            setResult(QuantitativeOrderDetailActivity.AppendSucc);
            finish();
        }
    }

    @Override
    public void getStakingPayOrderData(RegisterData registerData) {
        if (registerData.getStatus() == 0) {
            setResult(QuantitativeOrderDetailActivity.AppendSucc);
            edtInputmoney.setText("");
            loadData();
            if (EmptyUtils.isNotEmpty(btnQuantitativeapplyCloseclick.getTag())
                    && ((String) btnQuantitativeapplyCloseclick.getTag()).equalsIgnoreCase("all_close")) {
                finish();
            }
        } else {
            showToast(registerData.getMsg());
        }
    }

    @Override
    public void getStakingOrderAppendData(StakingOrderAppendData appendData) {

        if (appendData.getStatus() == 0) {
            DialogUtils.enterPayPsw(this, (pwd1) -> {
                preenter.getStakingPayOrderData(appendData.getData().getOrderSn(), pwd1);
            });
        } else {
            showToast(appendData.getMsg());
        }
    }

    @Override
    public void getStakingMiningMoneyDrawIndexData(StakingMiningMoneyDrawIndexData stakingMiningMoneyDrawIndexData) {

    }

    @Override
    public void getMiningWalletTypeIndexData(MiningWalletTypeIndexData miningWalletTypeIndexData) {

    }

    @Override
    public void getDrawIndexData(Object o) {

    }
}
